package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.os.service.FoodServiceS;
import com.os.serviceimpl.FoodServiceImplS;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class UpdateFoodControllerS extends HttpServlet{
	FoodServiceS fsc = new FoodServiceImplS();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		String fname = req.getParameter("fname");
		String ftype = req.getParameter("ftype");
		String fspecialty = req.getParameter("fspecialty");
		String furl = req.getParameter("furl");
		String fnew = req.getParameter("fnew");
		double fp = Double.valueOf(req.getParameter("fprice"));
		String fmaterial = req.getParameter("fmaterial");
		String fhasma = req.getParameter("fhasma");
		int fs = 0;
		int fn = 0;
		int fh = 0;
		if(fspecialty.equals("on")){
			fs = 1;
		}
		if(fnew.equals("on")){
			fn = 1;
		}
		if(fhasma.equals("on")){
			fh = 1;
		}
		int fid = Integer.parseInt(req.getParameter("fid"));
		boolean flag = fsc.updateFoodsS(fname, ftype, fs, furl, fn, fp, fmaterial, fh, fid);
		PrintWriter pw = resp.getWriter();
		JSONObject q = new JSONObject();
		q.put("flag", flag);
		pw.write(q.toString());
	}
}
